﻿using Dqs_DAL;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dqs_BLL
{
    public class Student_BLL
    {
        Student_DAL student_DAL = new Student_DAL();
        public StudentInfo IsLoginOfStudent(string name, string pwd)
        {
            return student_DAL.IsLoginOfAdmin(name, pwd);
        }

        public List<StudentInfo> GetStudents()
        {
            return student_DAL.QueryStudentInfo();
        }

		public string GetStudentName(int id)
		{
			foreach (var temp in student_DAL.QueryStudentInfo())
			{
				if (temp.Id == id)
				{
					return temp.FullName!;
				}
			}
			return "";
		}

		public List<StudentInfo> GetStudentInfoBySpellOrNum(string str, int type)
		{
			List<StudentInfo> list = new List<StudentInfo>();
			foreach (var temp in student_DAL.QueryStudentInfo())
			{
				if(type == 1)
				{
					if (temp.StuNum!.Contains(str))
					{
						list.Add(temp);
					}
				}
				else if (type == 2)
				{
					if (temp.FullName!.Contains(str)) 
					{
						list.Add(temp);
					}
				}				
			}
			return list;
		}

		public bool InsertStudentInfo(StudentInfo studentInfo)
		{
			return student_DAL.InsertStudentInfo(studentInfo);
		}

		public bool UpdateStudentInfoById(StudentInfo studentInfo)
		{
			return student_DAL.UpdateStudentInfoById(studentInfo);
		}

		public bool DeleteStudentInfoById(int studentId)
		{
			return student_DAL.DeleteStudentInfoById(studentId);
		}

	}
}
